package com.haierCamera.customapplication.ui.main;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.haierCamera.customapplication.BaseActivity;
import com.haierCamera.customapplication.R;
import com.haierCamera.customapplication.api.ApiService;
import com.haierCamera.customapplication.databinding.HzklActivityDeviceAlarmMsgBinding;
import com.haierCamera.customapplication.ui.business.Business;
import com.haierCamera.customapplication.ui.business.entity.AlarmMessageInfo;
import com.haierCamera.customapplication.ui.business.entity.RecordInfo;
import com.haierCamera.customapplication.ui.business.util.ImageHelper;
import com.haierCamera.customapplication.ui.custom.BaseListenerOnClik;
import com.haierCamera.customapplication.ui.mediaplay.MediaPlayActivity;
import com.haierCamera.customapplication.utils.DateUtil;
import com.haierCamera.customapplication.utils.DensityUtil;
import com.haierCamera.customapplication.utils.ResourceConvertUtils;
import com.haierCamera.customapplication.utils.android.HttpErrorProcess;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import dagger.Lazy;

public class HZKLAlarmMessageIntradayActivity extends BaseActivity {

    HzklActivityDeviceAlarmMsgBinding binding;

    List<AlarmMessageInfo> list_a = new ArrayList<>();
    AlarmMessageList2Adapter adapter;
    int WeekDay = -1;
    int selectItem = 6;

    @Inject
    Lazy<HttpErrorProcess> httpErrorProcessLazy;
    @Inject
    ApiService apiService;

    private TimePickerView pvCustomTime;

    private String selectDate;
    @Override
    public void onBackPressed() {
        finish();
        Business.getInstance().getmAlarmMessageInfoList().clear();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = DataBindingUtil.setContentView(this, R.layout.hzkl_activity_device_alarm_msg);
        binding.imgReturn.setOnClickListener((v)->{
            finish();
            Business.getInstance().getmAlarmMessageInfoList().clear();
        });

//        binding.tvTitle.setText(getIntent().getStringExtra("name"));
        binding.rcv.setLayoutManager(new LinearLayoutManager(this));
        adapter = new AlarmMessageList2Adapter(this);
        binding.rcv.setAdapter(adapter);
//        binding.tvToday.setText(DateUtil.getNowTime().substring(0,10));
        binding.tvDate.setText(DateUtil.getNowTime().substring(0,10));
        binding.layoutDate.setOnClickListener((v)->{
            initCustomTimePicker();
        });
        adapter.setOnItemOnClick(new BaseListenerOnClik() {
            @Override
            public void onClick(int position) {
                if (adapter.isEdit()) {
                    setEditView(false);
                    return;
                } else {

                    getRecord(getIntent().getStringExtra("devId")
                            ,list_a.get(position).getDeviceKey()
                            ,list_a.get(position).getLocalDate()
                            ,list_a.get(position).getLocalDate().substring(0,10) + " 23:59:59"
                            ,list_a.get(position).getPicUrl());

                }
            }
        });
        adapter.setOnCheckSeleckListener(new AlarmMessageList2Adapter.OnCheckSeleckListener() {
            @Override
            public void onSelectChange(int pos, boolean select) {
                if (!select) {
//                    binding.ivAllSelect.setImageResource(R.drawable.hzkl_all_select_not);
                } else if (select) {
                    boolean allSelect = true;
                    for (int i = 0; i < adapter.getData().size(); i++) {
                        if (!adapter.getData().get(i).isSelect()) {
                            allSelect = false;
                        }
                    }
                    if (allSelect) {
//                        binding.ivAllSelect.setImageResource(R.drawable.hzkl_all_selected);
                    }
                }
            }
        });

//        binding.ivAllSelect.setOnClickListener((v)->{
//            boolean isAll = true;
//            for (int i = 0; i < adapter.getData().size(); i++) {
//                if (!adapter.getData().get(i).isSelect()) {
//                    isAll = false;
//                }
//            }
//            setData(!isAll);
//            if (!isAll) {
//                binding.ivAllSelect.setImageResource(R.drawable.hzkl_all_selected);
//            } else {
//                binding.ivAllSelect.setImageResource(R.drawable.hzkl_all_select_not);
//            }
//        });

        binding.ivShowImg.setOnClickListener((v)->{
            binding.ivShowImg.setVisibility(View.GONE);
        });
        binding.rcv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (!adapter.isEdit()) {
                    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                        int lastPosition = layoutManager.findLastVisibleItemPosition();
                        if (lastPosition == adapter.getItemCount() - 1) {

                            if (list_a!=null && list_a.size()>0) {
                                queryMsg(list_a.get(list_a.size() - 1).getAlarmId() + ""
                                        , DateUtil.getSeveralBefore((6 - selectItem)).substring(0, 10)
                                        , DateUtil.getSeveralBefore((6 - selectItem)).substring(0, 10), true);
                            }

                        }
                    }
                }
            }
        });

        binding.swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                queryMsg("-1"
                        , selectDate
                        , selectDate,false);
            }
        });
        Business.getInstance().getmAlarmMessageInfoList().clear();
        selectDate = DateUtil.getNowTime().substring(0,10);
        queryMsg("-1"
                , selectDate
                , selectDate,false);
        init();
    }

    private void initCustomTimePicker() {
        /**
         * @description
         *
         * 注意事项：
         * 1.自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针.
         * 具体可参考demo 里面的两个自定义layout布局。
         * 2.因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
         * setRangDate方法控制起始终止时间(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
         */
        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        Calendar startDate = Calendar.getInstance();
        startDate.set(2010, 1, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2100,12,31);
        //时间选择器 ，自定义布局
        pvCustomTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                binding.tvDate.setText(getTime(date));
                Business.getInstance().getmAlarmMessageInfoList().clear();
                selectDate = getTime(date);
                queryMsg("-1", getTime(date),getTime(date),false);
            }
        })
                /*.setType(TimePickerView.Type.ALL)//default is all
                .setCancelText("Cancel")
                .setSubmitText("Sure")
                .setContentTextSize(18)
                .setTitleSize(20)
                .setTitleText("Title")
                .setTitleColor(Color.BLACK)
               /*.setDividerColor(Color.WHITE)//设置分割线的颜色
                .setTextColorCenter(Color.LTGRAY)//设置选中项的颜色
                .setLineSpacingMultiplier(1.6f)//设置两横线之间的间隔倍数
                .setTitleBgColor(Color.DKGRAY)//标题背景颜色 Night mode
                .setBgColor(Color.BLACK)//滚轮背景颜色 Night mode
                .setSubmitColor(Color.WHITE)
                .setCancelColor(Color.WHITE)*/
                /*.animGravity(Gravity.RIGHT)// default is center*/
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setLayoutRes(R.layout.hzkl_dialog_intraday_select_date, new CustomListener() {

                    @Override
                    public void customLayout(View v) {
                        final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                        TextView tvCancel = (TextView) v.findViewById(R.id.tv_cancel);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.returnData();
                                pvCustomTime.dismiss();
                            }
                        });
                        tvCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.dismiss();
                            }
                        });
                    }
                })
                .setContentTextSize(18)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "时", "分", "秒")
                .setLineSpacingMultiplier(2f)
                .setTextXOffset(0, 0, 0, 40, 0, -40)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(0x503366FF)

                .build();

        pvCustomTime.show();
    }


    private String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }


    private void setData (boolean isAll){
        if (isAll) {
            for (int i = 0; i < adapter.getData().size(); i++) {
                adapter.getData().get(i).setSelect(true);
            }
        } else {
            for (int i = 0; i < adapter.getData().size(); i++) {
                adapter.getData().get(i).setSelect(false);
            }
        }
        adapter.notifyDataSetChanged();
    }

    private void getRecord(String deviceId,String cameraPwd,String startTime,String endTime,String picUrl) {
        Log.i("TAG","getRecordList-from-" + startTime + "/" + "to-" + endTime);
        showLoadingDialog("加载中");
        Business.getInstance().queryRecordList2(deviceId
                ,cameraPwd
                , startTime
                , endTime
                , getIntent().getStringExtra("chnId")
                ,1
                ,2
                ,new Handler(){
                    @Override
                    public void handleMessage(@NonNull Message msg) {
                        super.handleMessage(msg);
//                        Log.i("TAG","what-" + msg.what);
                        if (msg.what == 0) {
                            List<RecordInfo> list = (List<RecordInfo>) msg.obj;
//                            Log.i("TAG","RecordList-" + list.size());
                            if ( list.size()>0) {

                                startActivity(new Intent(HZKLAlarmMessageIntradayActivity.this, MediaPlayActivity.class)
                                        .putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_RECORD)
                                        .putExtra("RESID", list.get(0).getId())
                                        .putExtra("RESNAME", getIntent().getStringExtra("name"))
                                        .putExtra("RESDEVICEID", list.get(0).getDeviceId())
                                        .putExtra("RESCHANNELID",Integer.parseInt(getIntent().getStringExtra("chnId")))
                                        .putExtra("RESPWD", list.get(0).getDeviceKey()));

                            } else {
                                toast("视频录制中");
                            }

                        } else {
                            if (msg.obj.toString()!=null
                                    &&msg.obj.toString().contains("存储")) {
                                toast("无存储卡");
                                if(picUrl != null && picUrl.length() > 0) {

                                    ImageHelper.loadCacheImage(picUrl
                                            ,deviceId
                                            ,cameraPwd != null ? cameraPwd : deviceId
                                            , new Handler(){
                                                @Override
                                                public void handleMessage(Message msg) {
                                                    super.handleMessage(msg);
                                                    try {
                                                        if(picUrl.hashCode() == msg.what && msg.obj != null){
//                                    holder.binding.ivScale.setImageDrawable((Drawable)msg.obj);
                                                            //得到资源文件的BitMap
//                                    Bitmap image= BitmapFactory.decodeResource(getResources(),R.drawable.dog);

                                                            BitmapDrawable bd = (BitmapDrawable) ((Drawable)msg.obj);
                                                            Bitmap image= bd.getBitmap();
                                                            //创建RoundedBitmapDrawable对象
                                                            RoundedBitmapDrawable roundImg = RoundedBitmapDrawableFactory
                                                                    .create(HZKLAlarmMessageIntradayActivity.this.getResources(),image);

                                                            binding.ivShowImg.setImageDrawable(roundImg);
                                                            binding.ivShowImg.setVisibility(View.VISIBLE);
                                                        }
                                                    } catch (Exception e) {
                                                        e.printStackTrace();
                                                    }
                                                }
                                            });
                                }
                            } else {
                                toast("请求失败-" + msg.what);
                            }
                        }
                        dismissLoadingDialog();
                    }
                });
    }

    private void queryMsg(String nextAlarmId, String startTime, String endTime, boolean isLoaded){
        if (!isLoaded) {
            if (list_a != null && list_a.size() != 0) {
                list_a.clear();
                adapter.notifyDataSetChanged();
            }
        }
        Log.i("TAG","nextAlarmId-" + nextAlarmId);
                Business.getInstance().queryAlarmMessageList2(getIntent().getStringExtra("devId")
                        , getIntent().getStringExtra("cameraPwd")
                        ,  startTime+ " 00:00:00"
                        , endTime+ " 23:59:59"
                        ,30
                        , nextAlarmId
                        , getIntent().getStringExtra("chnId")
                        ,new Handler() {
                            @Override
                            public void handleMessage(@NonNull Message msg) {
                                super.handleMessage(msg);
                                if (msg.what == 0) {
                                    List<AlarmMessageInfo> list = (List<AlarmMessageInfo>) msg.obj;
                                    Log.i("TAG","Al_list_size-" + list.size());
                                    if (list.size() !=0) {
                                        Log.i("TAG","upDate");
                                        for (int i = 0; i < list.size(); i++) {
                                            list.get(i).setName(getIntent().getStringExtra("name"));
                                        }
                                        list_a.addAll(list);
                                        adapter.upDate(list_a);

                                        Business.getInstance().getmAlarmMessageInfoList().clear();
                                    } else {
                                        toast("无更多数据");
                                    }
                                }

                                if (list_a !=null && list_a.size() > 0) {
                                    binding.rcv.setVisibility(View.VISIBLE);
                                    binding.ivEmpty.setVisibility(View.GONE);
                                } else {
                                    binding.ivEmpty.setVisibility(View.VISIBLE);
                                }
                                binding.swipe.setRefreshing(false);
                            }
                        });

    }

    private void deleteAlarmMsg(String indexId, String sn, String channelNo){
        showLoadingDialog();
            ResourceConvertUtils.convertToResource(apiService.deleteAlarmMsg(indexId, sn, channelNo))
                    .observe(this, resource -> {
                        assert resource != null;
                        switch (resource.status) {
                            case ERROR:
                                httpErrorProcessLazy.get().process(resource);
                                dismissLoadingDialog();
                                break;
                            case SUCCESS:
                                List<AlarmMessageInfo> list = new ArrayList<>();
                                for (int i = 0; i < list_a.size(); i++) {
                                    if (!list_a.get(i).isSelect()) {
                                        list.add(list_a.get(i));
                                    }
                                }
                                list_a = list;
                                adapter.upDate(list_a);
                                dismissLoadingDialog();
                                break;
                            case LOADING:
                                break;

                        }
                    });

    }

    private void setEditView(boolean edit) {
        if (edit) {
            adapter.setEdit(true);
            binding.btnDel.setVisibility(View.VISIBLE);
            binding.ivEditDone.setVisibility(View.VISIBLE);
            binding.ivEdit.setVisibility(View.GONE);
            binding.layoutDate.setVisibility(View.VISIBLE);
//            binding.imgReturn.setVisibility(View.GONE);
//            binding.ivAllSelect.setVisibility(View.VISIBLE);
        } else {
            adapter.setEdit(false);
            binding.btnDel.setVisibility(View.GONE);
            binding.ivEditDone.setVisibility(View.GONE);
            binding.ivEdit.setVisibility(View.VISIBLE);
            binding.layoutDate.setVisibility(View.VISIBLE);
//            binding.imgReturn.setVisibility(View.VISIBLE);
//            binding.ivAllSelect.setVisibility(View.GONE);
        }
    }

//    private void initLayout() {
//        runOnUiThread(()->{
//        if (selectItem == 6) {
//            binding.layout7.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek7.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate7.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        }else if (selectItem == 5) {
//            binding.layout6.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek6.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate6.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        } else if (selectItem == 4) {
//            binding.layout5.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek5.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate5.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        } else if (selectItem == 3) {
//            binding.layout4.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek4.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate4.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        } else if (selectItem == 2) {
//            binding.layout3.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek3.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate3.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        } else if (selectItem == 1) {
//            binding.layout2.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek2.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate2.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        } else if (selectItem == 0) {
//            binding.layout1.setBackgroundResource(R.color.HZKLtransparent);
//            binding.tvWeek1.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//            binding.tvDate1.setTextColor(getResources().getColor(R.color.hzkl_text_color_dark));
//        }
//        });
////        binding.layout1.setBackgroundResource(R.color.HZKLtransparent);
////        binding.layout2.setBackgroundResource(R.color.HZKLtransparent);
////        binding.layout3.setBackgroundResource(R.color.HZKLtransparent);
////        binding.layout4.setBackgroundResource(R.color.HZKLtransparent);
////        binding.layout5.setBackgroundResource(R.color.HZKLtransparent);
////        binding.layout6.setBackgroundResource(R.color.HZKLtransparent);
//
//    }

    private void init() {
        WeekDay = DateUtil.getDayofWeek();
//        binding.layout7.setBackgroundResource(R.drawable.hzkl_button_blue);
//        binding.tvDate7.setTextColor(getResources().getColor(R.color.hzkl_white));
//        binding.tvWeek7.setTextColor(getResources().getColor(R.color.hzkl_white));
//        binding.tvDate7.setText(DateUtil.getSeveralBefore(0).substring(8,10) );
//        binding.tvDate6.setText(DateUtil.getSeveralBefore(1).substring(8,10) );
//        binding.tvDate5.setText(DateUtil.getSeveralBefore(2).substring(8,10) );
//        binding.tvDate4.setText(DateUtil.getSeveralBefore(3).substring(8,10) );
//        binding.tvDate3.setText(DateUtil.getSeveralBefore(4).substring(8,10) );
//        binding.tvDate2.setText(DateUtil.getSeveralBefore(5).substring(8,10) );
//        binding.tvDate1.setText(DateUtil.getSeveralBefore(6).substring(8,10) );

        binding.ivEdit.setOnClickListener((v)->{
            setEditView(true);
        });

        binding.ivEditDone.setOnClickListener((v)->{
            setEditView(false);
        });

        binding.btnDel.setOnClickListener((v)->{
            List<String> list = new ArrayList<>();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < list_a.size(); i++) {
                if (list_a.get(i).isSelect()) {
//                    Log.i("TAG","index-" + i);
                    list.add(list_a.get(i).getAlarmId()+"");

                }
            }
            for (int i = 0; i < list.size(); i++) {
                if (sb.length() > 0) {//该步即不会第一位有逗号，也防止最后一位拼接逗号！
                    sb.append(",");
                }
                sb.append(list.get(i));
            }

            deleteAlarmMsg(sb.toString(), getIntent().getStringExtra("devId"), list_a.get(0).getChnlUuid());


        });
//        if (WeekDay == 1) {//周日
//            binding.tvWeek7.setText("日");
//            binding.tvWeek6.setText("六");
//            binding.tvWeek5.setText("五");
//            binding.tvWeek4.setText("四");
//            binding.tvWeek3.setText("三");
//            binding.tvWeek2.setText("二");
//            binding.tvWeek1.setText("一");
//
//        } else if (WeekDay == 2) {//周一
//            binding.tvWeek7.setText("一");
//            binding.tvWeek6.setText("日");
//            binding.tvWeek5.setText("六");
//            binding.tvWeek4.setText("五");
//            binding.tvWeek3.setText("四");
//            binding.tvWeek2.setText("三");
//            binding.tvWeek1.setText("二");
//
//        } else if (WeekDay == 3) {//周二
//            binding.tvWeek7.setText("二");
//            binding.tvWeek6.setText("一");
//            binding.tvWeek5.setText("日");
//            binding.tvWeek4.setText("六");
//            binding.tvWeek3.setText("五");
//            binding.tvWeek2.setText("四");
//            binding.tvWeek1.setText("三");
//
//        } else if (WeekDay == 4) {//周三
//            binding.tvWeek7.setText("三");
//            binding.tvWeek6.setText("二");
//            binding.tvWeek5.setText("一");
//            binding.tvWeek4.setText("日");
//            binding.tvWeek3.setText("六");
//            binding.tvWeek2.setText("五");
//            binding.tvWeek1.setText("四");
//
//        } else if (WeekDay == 5) {//周四
//            binding.tvWeek4.setText("四");
//            binding.tvWeek3.setText("三");
//            binding.tvWeek2.setText("二");
//            binding.tvWeek1.setText("一");
//            binding.tvWeek7.setText("日");
//            binding.tvWeek6.setText("六");
//            binding.tvWeek5.setText("五");
//
//        } else if (WeekDay == 6) {//周五
//            binding.tvWeek7.setText("五");
//            binding.tvWeek6.setText("四");
//            binding.tvWeek5.setText("三");
//            binding.tvWeek4.setText("二");
//            binding.tvWeek3.setText("一");
//            binding.tvWeek2.setText("日");
//            binding.tvWeek1.setText("六");
//
//        } else if (WeekDay == 7) {//周六
//            binding.tvWeek7.setText("六");
//            binding.tvWeek6.setText("五");
//            binding.tvWeek5.setText("四");
//            binding.tvWeek4.setText("三");
//            binding.tvWeek3.setText("二");
//            binding.tvWeek2.setText("一");
//            binding.tvWeek1.setText("日");
//
//        }
//
//        binding.layout1.setOnClickListener((v)->{
//            if (selectItem ==0) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 0;
//            binding.layout1.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate1.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek1.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(6).substring(0,10)
//                    ,DateUtil.getSeveralBefore(6).substring(0,10),false);
//        });
//        binding.layout2.setOnClickListener((v)->{
//            if (selectItem ==1) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 1;
//            binding.layout2.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate2.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek2.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(5).substring(0,10)
//                    ,DateUtil.getSeveralBefore(5).substring(0,10),false);
//        });
//        binding.layout3.setOnClickListener((v)->{
//            if (selectItem ==2) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 2;
//            binding.layout3.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate3.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek3.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(4).substring(0,10)
//                    ,DateUtil.getSeveralBefore(4).substring(0,10),false);
//        });
//        binding.layout4.setOnClickListener((v)->{
//            if (selectItem ==3) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 3;
//            binding.layout4.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate4.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek4.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(3).substring(0,10)
//                    ,DateUtil.getSeveralBefore(3).substring(0,10),false);
//        });
//        binding.layout5.setOnClickListener((v)->{
//            if (selectItem ==4) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 4;
//            binding.layout5.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate5.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek5.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(2).substring(0,10)
//                    ,DateUtil.getSeveralBefore(2).substring(0,10),false);
//        });
//        binding.layout6.setOnClickListener((v)->{
//            if (selectItem ==5) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 5;
//            binding.layout6.setBackgroundResource(R.drawable.hzkl_button_blue);
//            runOnUiThread(()->{
//                binding.tvDate6.setTextColor(getResources().getColor(R.color.hzkl_white));
//                binding.tvWeek6.setTextColor(getResources().getColor(R.color.hzkl_white));
//            });
//
//            queryMsg("-1",DateUtil.getSeveralBefore(1).substring(0,10)
//                    ,DateUtil.getSeveralBefore(1).substring(0,10),false);
//        });
//        binding.layout7.setOnClickListener((v)->{
//            if (selectItem ==6) {
//                return;
//            }
//            Business.getInstance().getmAlarmMessageInfoList().clear();
//            initLayout();
//            selectItem = 6;
//            binding.layout7.setBackgroundResource(R.drawable.hzkl_button_blue);
//            binding.tvDate7.setTextColor(getResources().getColor(R.color.hzkl_white));
//            binding.tvWeek7.setTextColor(getResources().getColor(R.color.hzkl_white));
//            queryMsg("-1",DateUtil.getSeveralBefore(0).substring(0,10)
//                    ,DateUtil.getSeveralBefore(0).substring(0,10),false);
//        });

    }
}
